package com.gree.changying.activity.mainactivity.framgent;


import android.os.Handler;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.gree.changying.R;
import com.gree.changying.activity.base.BasePageFragment;
import com.gree.changying.activity.mainactivity.framgent.phfrm.adapter.PhAdapter;
import com.gree.changying.activity.mainactivity.framgent.phfrm.bean.Paihan;
import com.gree.changying.view.AutoRecyclerView;
import com.gree.changying.widget.refreshLayout.MaterialSmoothRefreshLayout;
import com.gree.changying.widget.refreshLayout.lib.SmoothRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class PhFrm extends BasePageFragment implements   SmoothRefreshLayout.OnRefreshListener{
    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        init();
        initRv();
    }

    /**
     * 新闻
     */
    @Bind(R.id.rv)
    AutoRecyclerView rv;
    private PhAdapter rvAdapter;
    private void initRv(){
        rv.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        rvAdapter = new PhAdapter(R.layout.item_paihangban,getZxzx());
        rv.setAdapter(rvAdapter);
    }

    private Object[][] zxzxList = {
            {1,R.drawable.touxiang,"测试人",10,10,10,10,100},
            {2,R.drawable.touxiang,"测试人",2,22,10,10,87},
            {3,R.drawable.touxiang,"测试人",10,10,10,10,78},
            {4,R.drawable.touxiang,"测试人",10,10,10,10,77},
            {5,R.drawable.touxiang,"测试人",10,10,10,10,65},
            {6,R.drawable.touxiang,"测试人",10,10,10,10,55},
            {7,R.drawable.touxiang,"测试人",10,10,10,10,55},
            {8,R.drawable.touxiang,"测试人",10,10,10,10,55},
            {9,R.drawable.touxiang,"测试人",10,10,10,10,55},
            {10,R.drawable.touxiang,"测试人",10,10,10,10,45},
            {11,R.drawable.touxiang,"测试人",10,10,10,10,34},
            {12,R.drawable.touxiang,"测试人",10,10,10,10,34},
            {13,R.drawable.touxiang,"测试人",10,10,10,10,34},
            {14,R.drawable.touxiang,"测试人",10,10,10,10,34},
            {15,R.drawable.touxiang,"测试人",10,10,10,10,33},
            {16,R.drawable.touxiang,"测试人",10,10,10,10,33},
            {17,R.drawable.touxiang,"测试人",10,10,10,10,32},
            {18,R.drawable.touxiang,"测试人",10,10,10,10,29},
            {19,R.drawable.touxiang,"测试人",10,10,10,10,26},
            {20,R.drawable.touxiang,"测试人",4,3,3,5,13}
    };
    private List<Paihan> getZxzx(){
        List<Paihan> rmsses = new ArrayList<>();
        for(Object[] o:zxzxList){
            Paihan rmss = new Paihan();
            rmss.setNum((int)o[0]);
            rmss.setImg((int)o[1]);
            rmss.setName((String)o[2]);
            rmss.setZcs((int)o[3]);
            rmss.setHong((int)o[4]);
            rmss.setHe((int)o[5]);
            rmss.setHei((int)o[6]);
            rmss.setSl((int)o[7]);
            rmsses.add(rmss);
        }
        return rmsses;
    }

    @Bind(R.id.refreshLayout)
    MaterialSmoothRefreshLayout refreshLayout;
    @Override
    public void onRefreshing() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.refreshComplete();
            }
        },1000);
    }

    @Override
    public void onLoadingMore() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.frm_ph;
    }

    private void init(){
        refreshLayout.setDisableLoadMore(true);
        refreshLayout.setEnableAutoRefresh(false);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setDisableLoadMoreWhenContentNotFull(true);
        refreshLayout.setEnableAutoLoadMore(false);
        refreshLayout.autoRefresh(true);
        refreshLayout.autoLoadMore(false);
    }
}
